package com.wut.easyexcel.common.enums;

import cn.hutool.core.util.StrUtil;
import com.wut.core.common.enums.BaseEnum;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 性别
 */
@Getter
@AllArgsConstructor
public enum SexEnum implements BaseEnum {

    MAN(0, "男"),
    WOMAN(1, "女");

    private final Integer code;
    private final String name;

    public static String getNameByCode(Integer code) {
        for (SexEnum sexEnum : SexEnum.values()) {
            if (Objects.equals(sexEnum.getCode(), code)) {
                return sexEnum.getName();
            }
        }
        return StrUtil.EMPTY;
    }

    public static Integer getCodeByName(String name) {
        for (SexEnum sexEnum : SexEnum.values()) {
            if (Objects.equals(sexEnum.getName(), name)) {
                return sexEnum.getCode();
            }
        }
        return null;
    }

    @Override
    public String getKey() {
        return String.valueOf(code);
    }

    @Override
    public String getValue() {
        return name;
    }
}
